package com.xyh.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:kyle
 * @Date:2020/12/21 - 16:29
 * @Project:spring_demo1
 * @Package:com.xyh.interceptor
 * @Version:1.0
 */
public class LoginInterceptor implements HandlerInterceptor {
    //进入Controller之间进行验证
    //这个方法有返回值，如果为true，可以进入Controller
    //因此，一般我们需要验证的一些内容都放入到preHandle方法中
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("==========LoginInterceptor.preHandle==========");
        String uri = request.getRequestURI();
        System.out.println("uri = " + uri);

        if(uri.indexOf("login") != -1){
            return true;
        }
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
